<!DOCTYPE html>
<html>
{include file="public/header"}
<body>
{include file="public/x-nav"}
<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so">
            <input type="text" name="position_code"  placeholder="请输入名称" autocomplete="off" class="layui-input">
            <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
    </div>
    <xblock>
        <button class="layui-btn" onclick="x_admin_show('添加','add.html',900,650)"><i class="layui-icon"></i>添加标签</button>
    </xblock>
    <table class="layui-table">
        <thead>
        <tr>
            <th>ID</th>
            <th>名称</th>
            <th>操作</th>
        </thead>
        <tbody>
        {volist name="list" id="item"}
        <tr>
            <td>{$item->id}</td>
            <td><span class="layui-badge {$item->id%2==0 ? 'layui-bg-green' : 'layui-bg-red'} ">{$item->tag_name}</span></td>
            <td class="td-manage">
                <a title="编辑"  onclick="x_admin_show('编辑','edit/id/{$item->id}',900,650)" href="javascript:;">
                    <i class="layui-icon">&#xe642;</i>
                </a>
                <a title="删除" onclick="del(this,'{$item->id}')" href="javascript:;">
                    <i class="layui-icon">&#xe640;</i>
                </a>
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
</div>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });
    });

    function del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            //发异步删除数据
            $.post("{:url('delete')}",{id:id},function(response){
                if(response.code === 200){
                    $(obj).parents("tr").remove();
                    layer.msg('已删除!', {icon: 1, time: 1000});
                }else{
                    layer.msg(response.msg, {icon: 5, time: 1000});
                }
            },'json');
        });
    }

</script>
</body>

</html>